﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'FN' AND name = 'GetStockByDepartamento')
	BEGIN
		DROP  Function  GetStockByDepartamento
	END
GO

CREATE FUNCTION GetStockByDepartamento
(
	@IdDepartamento int,
	@IdProducto int
)
RETURNS int
AS
BEGIN	
	DECLARE @stock int
	SET @stock = ISNULL((SELECT Stock FROM ProductoDepartamento WHERE IdDepartamento=@IdDepartamento AND IdProducto=@IdProducto), 0)
	RETURN @stock
END

GO 
 